﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Seminarska
{
    /// <summary>
    /// Interaction logic for Pecati.xaml
    /// </summary>
    public partial class Pecati : Window
    {
        //AJAJAJAJAJJAJAJAJAJ
        //JAJAJAJAJJAJAJAJJAJ
        public Pecati()
        {
            InitializeComponent();

            Rect r = Properties.Settings.Default.Window;
            this.Top = r.Top;
            this.Left = r.Left;
        }

        private void btnPecati_Click(object sender, RoutedEventArgs e)
        {
            Properties.Settings.Default.Window = this.RestoreBounds;
            Properties.Settings.Default.Save();
            this.Close();
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            Properties.Settings.Default.Window = this.RestoreBounds;
            Properties.Settings.Default.Save();
        }


        private enum Operation
        {
            None,
            Subtract,
            OneX

        }
        private Operation LastOper;
        private string _display;
        private bool _erasediplay;
        private string _last_val;

        private string LastValue
        {
            get
            {
                if (_last_val == string.Empty)
                    return "0";
                return _last_val;

            }
            set
            {
                _last_val = value;
            }
        }

        private bool EraseDisplay
        {
            get
            {
                return _erasediplay;

            }
            set
            {
                _erasediplay = value;
            }
        }

        private string Display
        {
            get
            {
                return _display;
            }
            set
            {
                _display = value;
            }
        }

        private void DigitBtn_Click(object sender, RoutedEventArgs e)
        {
            string s = ((Button)sender).Content.ToString();
            //NumPad digits = new NumPad();

            char[] ids = s.ToCharArray();
            ProcessKey(ids[0]);
        }

        private void ProcessKey(char c)
        {
            if (EraseDisplay)
            {
                Display = string.Empty;
                EraseDisplay = false;
            }
            AddToDisplay(c);
        }

        private void UpdateDisplay()
        {
            txtKupuvac.Text = Display;
        }

        private void AddToDisplay(char c)
        {

            if (c >= '0' && c <= '9')
            {
                Display = Display + c;
            }

            UpdateDisplay();
        }

        private void ProcessOperation(string s)
        {
            LastOper = Operation.None;
            Display = LastValue;
            UpdateDisplay();

        }

        private void btnC_Click(object sender, RoutedEventArgs e)
        {
            ProcessOperation(((Button)sender).Name.ToString());

        }

    }
}
